package com.fbinggun.fattribute.papi;


import com.fbinggun.fattribute.data.DataManage;
import com.fbinggun.fattribute.data.PlayerData;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class AttributePAPI extends PlaceholderExpansion {
    JavaPlugin plugin;

    public AttributePAPI(JavaPlugin plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean persist() {
        return true;
    }

    @Override
    public boolean canRegister() {
        return true;
    }

    @Override
    public String getAuthor() {
        return plugin.getDescription().getAuthors().toString();
    }


    @Override
    public String getIdentifier() {
        return "FAttribute";
    }

    @Override
    public String getVersion() {
        return plugin.getDescription().getVersion();
    }

    //FAttribute_[key] 属性值
    @Override
    public String onPlaceholderRequest(Player player, String identifier) {
        String[] args=identifier.split("_");
        if(args.length==1){
            String key =args[0];
            PlayerData playerData = DataManage.getPlayerData(player);
            return String.valueOf(playerData.getValue(key));
        }
        return identifier;
    }
}